#include <string>
#include "atomic.h"
#include "message.h"
#include "mainsimu.h"
#include "strutil.h"
#include "../HeadFile/MES_splitting_3_model.h"


/**** the Constructor ****/
MES_splitting_3_model::MES_splitting_3_model( const string &name)
: Atomic( name )
, MES_splitting_3_stream_LD_1( this->addInputPort( "MES_splitting_3_stream_LD_1") )
, MES_splitting_3_stream_LD_3( this->addOutputPort( "MES_splitting_3_stream_LD_3") )
, MES_splitting_3_stream_LD_2( this->addOutputPort( "MES_splitting_3_stream_LD_2") )
{

		
	string tmpval1(MainSimulator::Instance().getParameter( this->description(), "MES_splitting_3_stream_LD_1_opt_flowrate_val" ));
	string tmpval2(MainSimulator::Instance().getParameter( this->description(), "MES_splitting_3_stream_LD_2_opt_flowrate_val" ));
	string tmpval3(MainSimulator::Instance().getParameter( this->description(), "MES_splitting_3_stream_LD_3_opt_flowrate_val" ));

	MES_splitting_3_stream_LD_1_opt_flowrate_val = str2float(tmpval1);
	MES_splitting_3_stream_LD_2_opt_flowrate_val = str2float(tmpval2);
	MES_splitting_3_stream_LD_3_opt_flowrate_val = str2float(tmpval3);

		
		
}


/*** the initFunction ***/
Model &MES_splitting_3_model::initFunction()
{

		
	count = 0;
	delay = "00:00:00:00";
	passivate();
	return *this;
		
		
}

/*** the externalFunction ***/
Model &MES_splitting_3_model::externalFunction( const ExternalMessage &msg )
{

			
	if( msg.port() == MES_splitting_3_stream_LD_1 ){
		MES_splitting_3_stream_LD_1_flowrate = msg.value();
		holdIn( active, delay);
	}
	return *this;
		
		
}

/*** the internalFunction ***/
Model &MES_splitting_3_model::internalFunction( const InternalMessage &msg )
{

			
	passivate();
	return *this;
		
		
}

/*** the outputFunction ***/
Model &MES_splitting_3_model::outputFunction( const InternalMessage &msg )
{

		
	MES_splitting_3_stream_LD_2_flowrate = MES_splitting_3_stream_LD_1_flowrate * (MES_splitting_3_stream_LD_2_opt_flowrate_val / MES_splitting_3_stream_LD_1_opt_flowrate_val);
	MES_splitting_3_stream_LD_3_flowrate = MES_splitting_3_stream_LD_1_flowrate * (MES_splitting_3_stream_LD_3_opt_flowrate_val / MES_splitting_3_stream_LD_1_opt_flowrate_val);
	sendOutput( msg.time(), MES_splitting_3_stream_LD_2, MES_splitting_3_stream_LD_2_flowrate);
	sendOutput( msg.time(), MES_splitting_3_stream_LD_3, MES_splitting_3_stream_LD_3_flowrate);
	return *this;
		
		
}

